package services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.aton.db.SessionFactory;

import models.DeviceHealth;
import models.mappers.BackInfoMapper;
import models.mappers.DeviceHealthMapper;
import vos.BackInfoVo;
import vos.DeviceHealthSearchVo;
import vos.DeviceHealthVo;
import vos.DeviceSickSearchVo;

public class DeviceHealthService {
	/**
	 * 获取统计记录
	 *
	 * @Title: listDeviceHealth 
	 * @param vo
	 * @return
	 * @return: List<BackInfoVo>
	 */
	public static List<BackInfoVo> listDeviceHealth(DeviceHealthSearchVo vo) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DeviceHealthMapper mapper = ss.getMapper(DeviceHealthMapper.class);
            return mapper.listDeviceHealth(vo);
        } finally {
            ss.close();
        }
	}
	/**
	 * 统计统计记录条数
	 *
	 * @Title: countDeviceHealth 
	 * @param vo
	 * @return
	 * @return: long
	 */
	public static long countDeviceHealth(DeviceHealthSearchVo vo) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DeviceHealthMapper mapper = ss.getMapper(DeviceHealthMapper.class);
            return mapper.countDeviceHealth(vo);
        } finally {
            ss.close();
        }
	}
	/**
	 * 保存设备不健康记录
	 *
	 * @Title: save 
	 * @param healths
	 * @return: void
	 */
	public static void save(List<DeviceHealth> healths) {
		// TODO Auto-generated method stub
		SqlSession ss = SessionFactory.getSqlSessionWithoutAutoCommit();
		try {
			DeviceHealthMapper mapper = ss.getMapper(DeviceHealthMapper.class);
            Map<String,Object> map=new HashMap<String,Object>();
            map.put("lists", healths);
			mapper.saveModel(map);
            ss.commit();
        }catch(Exception e){
        	ss.rollback();
        	e.printStackTrace();
        } finally {
            ss.close();
        }
	}
	/**
	 * 统计不健康记录总数
	 *
	 * @Title: countDeviceSick 
	 * @param vo
	 * @return
	 * @return: long
	 */
	public static long countDeviceSick(DeviceSickSearchVo vo) {
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DeviceHealthMapper mapper = ss.getMapper(DeviceHealthMapper.class);
            return mapper.countDeviceSick(vo);
        } finally {
            ss.close();
        }
	}
	/**
	 * 获取不健康记录列表
	 *
	 * @Title: listDeviceSick 
	 * @param vo
	 * @return
	 * @return: List<DeviceHealthVo>
	 */
	public static List<DeviceHealthVo> listDeviceSick(DeviceSickSearchVo vo) {
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DeviceHealthMapper mapper = ss.getMapper(DeviceHealthMapper.class);
            return mapper.listDeviceSick(vo);
        } finally {
            ss.close();
        }
	}
	/**
	 * 导出设备不健康列表
	 *
	 * @Title: exportSickXls 
	 * @param vo
	 * @return
	 * @return: List<DeviceHealthVo>
	 */
	public static List<DeviceHealthVo> exportSickXls(DeviceSickSearchVo vo) {
		SqlSession ss = SessionFactory.getSqlSession();
		try {
			DeviceHealthMapper mapper = ss.getMapper(DeviceHealthMapper.class);
            return mapper.exportSickXls(vo);
        } finally {
            ss.close();
        }
	}

}
